//
//  XTToast.swift
//  XTToast_Example
//
//  Created by 王叶庆 on 2020/9/24.
//  Copyright © 2020 CocoaPods. All rights reserved.
//

import UIKit
import Chrysan

public let XTToastShowDuration = 1.5

public class XTToast {
    private class var window: UIWindow? {
        return UIApplication.shared.windows.first { (item) -> Bool in
            item.frame == UIScreen.main.bounds && !item.isHidden
        }
    }
    public class func message(_ message: String, hideAfterDelay: Double = XTToastShowDuration) {
        XTToast.window?.chrysan.showHUD(.plain(message: message), hideAfterDelay: hideAfterDelay)
    }
    
    public class func loading(_ message: String? = nil) {
        XTToast.window?.chrysan.showHUD(.loading(message: message))
    }
    
    public class func hide() {
        XTToast.window?.chrysan.hide()
    }
    
    public class func progress(_ progress: Double, message: String? = nil, title: String? = nil) {
        XTToast.window?.chrysan.showHUD(progress: progress, message: message, progressText: title)
    }
    
    public class func error(_ message: String? = nil, hideAfterDelay: Double = XTToastShowDuration) {
        XTToast.window?.chrysan.showHUD(.failure(message: message), hideAfterDelay: hideAfterDelay)
    }
    
    public class func success(_ message: String? = nil, hideAfterDelay: Double = XTToastShowDuration) {
        XTToast.window?.chrysan.showHUD(.success(message: message), hideAfterDelay: hideAfterDelay)
    }
}
